// lib.rs - 鸿蒙平台性能监控动态库示例

use napi_derive_ohos::napi;

#[napi]
pub struct PerformanceData {
    cpu_usage: f64,    // CPU使用率，百分比，浮点数用f64
    memory_usage: f64, // 内存使用率，百分比
}

#[napi]
impl PerformanceData {
    #[napi(constructor)]
    pub fn new(cpu_usage: f64, memory_usage: f64) -> Self {
        Self {
            cpu_usage,
            memory_usage,
        }
    }

    #[napi(getter)]
    pub fn cpu_usage(&self) -> f64 {
        self.cpu_usage
    }

    #[napi(getter)]
    pub fn memory_usage(&self) -> f64 {
        self.memory_usage
    }
}

#[napi]
pub fn monitor_performance(data: &PerformanceData) -> String {
    format!(
        "CPU使用率: {:.2}%，内存使用率: {:.2}%",
        data.cpu_usage, data.memory_usage
    )
}

#[napi]
pub fn get_current_performance() -> PerformanceData {
    PerformanceData {
        cpu_usage: 65.0,
        memory_usage: 75.0,
    }
}

